// 这是通过appTool自动生成的rpcx代码，请勿修改
package toolGen

import (
	"gitee.com/kinwyb/workflow/agent/http/controller"
	"gitee.com/kinwyb/workflow/engine"
	"gitee.com/kinwyb/workflow/public"
	"gitee.com/kinwyb/workflow/storage"
	"net/http"

	"gitee.com/kinwyb/appTools/appTool"
	"gitee.com/kinwyb/conv"
	"github.com/emicklei/go-restful"
)

func getContextValue(request *restful.Request) *public.ContextValue {
	ret := public.ContextValue{
		UserID:   request.HeaderParameter("UserID"),
		UserName: request.HeaderParameter("UserName"),
		OrgID:    request.HeaderParameter("OrgID"),
	}
	return &ret
}

func flowSaveBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	var flow engine.Flow
	errBody := respCtx.ParamDecode(&flow)
	if errBody != nil {
		return
	}
	nodeID, err := controller.FlowSave(flow, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nodeID)
}

// FlowSave 流程保存
// workflowAPI.go  FlowSave
func FlowSave(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Reads(engine.Flow{})
	rb.To(flowSaveBuilder)
	rb.Doc("流程保存")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func flowQueryBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	flowID := request.QueryParameter("flowID")
	if flowID == "" {
		respCtx.ParamMissing("flowID")
		return
	}
	F, err := controller.FlowQuery(flowID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(F)
}

// FlowQuery 查询一个流程
// workflowAPI.go  FlowQuery
func FlowQuery(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("flowID", "流程ID").Required(true).DataType("string"))
	rb.To(flowQueryBuilder)
	rb.Doc("查询一个流程")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", engine.Flow{})
	return rb
}

func flowQueryNodesBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	flowID := request.QueryParameter("flowID")
	if flowID == "" {
		respCtx.ParamMissing("flowID")
		return
	}
	s, err := controller.FlowQueryNodes(flowID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// FlowQueryNodes 查询流程节点列表
// workflowAPI.go  FlowQueryNodes
func FlowQueryNodes(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("flowID", "流程ID").Required(true).DataType("string"))
	rb.To(flowQueryNodesBuilder)
	rb.Doc("查询流程节点列表")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", []storage.Node{})
	return rb
}

func workFlowCreateBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	flowID := request.QueryParameter("flowID")
	if flowID == "" {
		respCtx.ParamMissing("flowID")
		return
	}
	workFlowCode := request.QueryParameter("workFlowCode")
	if workFlowCode == "" {
		respCtx.ParamMissing("workFlowCode")
		return
	}
	workFlowName := request.QueryParameter("workFlowName")
	if workFlowName == "" {
		respCtx.ParamMissing("workFlowName")
		return
	}
	s, err := controller.WorkFlowCreate(flowID, workFlowCode, workFlowName, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// WorkFlowCreate 创建一个工作流
// workflowAPI.go  WorkFlowCreate
func WorkFlowCreate(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("flowID", "流程ID").Required(true).DataType("string"))
	rb.Param(restful.QueryParameter("workFlowCode", "工作流编码").Required(true).DataType("string"))
	rb.Param(restful.QueryParameter("workFlowName", "工作流名称").Required(true).DataType("string"))
	rb.To(workFlowCreateBuilder)
	rb.Doc("创建一个工作流")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", "")
	return rb
}

func workCreateBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	var req engine.WorkCreateReq
	errBody := respCtx.ParamDecode(&req)
	if errBody != nil {
		return
	}
	s, err := controller.WorkCreate(req, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// WorkCreate 创建一个工作
// workflowAPI.go  WorkCreate
func WorkCreate(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Reads(engine.WorkCreateReq{})
	rb.To(workCreateBuilder)
	rb.Doc("创建一个工作")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", "")
	return rb
}

func workNodeDoBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workDetailID := request.QueryParameter("workDetailID")
	if workDetailID == "" {
		respCtx.ParamMissing("workDetailID")
		return
	}
	isPassV := request.QueryParameter("isPass")
	if isPassV == "" {
		respCtx.ParamMissing("isPass")
		return
	}
	isPass := conv.ToBool(isPassV)
	memo := request.QueryParameter("memo")
	nextID, err := controller.WorkNodeDo(workDetailID, isPass, memo, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nextID)
}

// WorkNodeDo 工作节点执行
// workflowAPI.go  WorkNodeDo
func WorkNodeDo(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workDetailID", "工作节点ID").Required(true).DataType("string"))
	rb.Param(restful.QueryParameter("isPass", "是否通过").Required(true).DataType("bool"))
	rb.Param(restful.QueryParameter("memo", "备注描述").DataType("string"))
	rb.To(workNodeDoBuilder)
	rb.Doc("工作节点执行")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func flowRouteQueryBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	routeID := request.QueryParameter("routeID")
	if routeID == "" {
		respCtx.ParamMissing("routeID")
		return
	}
	F, err := controller.FlowRouteQuery(routeID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(F)
}

// FlowRouteQuery 流程公式查询
// api.go  FlowRouteQuery
func FlowRouteQuery(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("routeID", "流程公式ID").Required(true).DataType("string"))
	rb.To(flowRouteQueryBuilder)
	rb.Doc("流程公式查询")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", engine.FlowRoute{})
	return rb
}

func workNodesBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workID := request.QueryParameter("workID")
	if workID == "" {
		respCtx.ParamMissing("workID")
		return
	}
	s, err := controller.WorkNodes(workID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// WorkNodes 查询所有工作节点
// api.go  WorkNodes
func WorkNodes(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workID", "工作ID").Required(true).DataType("string"))
	rb.To(workNodesBuilder)
	rb.Doc("查询所有工作节点")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", []*storage.WorkNode{})
	return rb
}

func enableWorkFlowBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workFlowID := request.QueryParameter("workFlowID")
	if workFlowID == "" {
		respCtx.ParamMissing("workFlowID")
		return
	}
	err := controller.EnableWorkFlow(workFlowID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// EnableWorkFlow 启用工作流
// api.go  EnableWorkFlow
func EnableWorkFlow(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workFlowID", "工作流ID").Required(true).DataType("string"))
	rb.To(enableWorkFlowBuilder)
	rb.Doc("启用工作流")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func disableWorkFlowBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workFlowID := request.QueryParameter("workFlowID")
	if workFlowID == "" {
		respCtx.ParamMissing("workFlowID")
		return
	}
	err := controller.DisableWorkFlow(workFlowID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// DisableWorkFlow 禁用工作流
// api.go  DisableWorkFlow
func DisableWorkFlow(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workFlowID", "工作流ID").Required(true).DataType("string"))
	rb.To(disableWorkFlowBuilder)
	rb.Doc("禁用工作流")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func flowNodeQueryBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	nodeID := request.QueryParameter("nodeID")
	if nodeID == "" {
		respCtx.ParamMissing("nodeID")
		return
	}
	N, err := controller.FlowNodeQuery(nodeID)
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(N)
}

// FlowNodeQuery 流程节点查询
// api.go  FlowNodeQuery
func FlowNodeQuery(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("nodeID", "工作流ID").Required(true).DataType("string"))
	rb.To(flowNodeQueryBuilder)
	rb.Doc("流程节点查询")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", storage.Node{})
	return rb
}

func flowNodeUpdateBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	var req engine.Node
	errBody := respCtx.ParamDecode(&req)
	if errBody != nil {
		return
	}
	err := controller.FlowNodeUpdate(req, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// FlowNodeUpdate 流程节点更新
// api.go  FlowNodeUpdate
func FlowNodeUpdate(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Reads(engine.Node{})
	rb.To(flowNodeUpdateBuilder)
	rb.Doc("流程节点更新")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func flowDelBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	flowID := request.QueryParameter("flowID")
	if flowID == "" {
		respCtx.ParamMissing("flowID")
		return
	}
	err := controller.FlowDel(flowID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// FlowDel 工作流删除
// api.go  FlowDel
func FlowDel(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("flowID", "流程ID").Required(true).DataType("string"))
	rb.To(flowDelBuilder)
	rb.Doc("工作流删除")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func waitDoWorkListBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workFlowCode := request.QueryParameter("workFlowCode")
	userID := request.QueryParameter("userID")
	if userID == "" {
		respCtx.ParamMissing("userID")
		return
	}
	s, err := controller.WaitDoWorkList(workFlowCode, userID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// WaitDoWorkList 待工作列表
// api.go  WaitDoWorkList
func WaitDoWorkList(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workFlowCode", "工作流编码").DataType("string"))
	rb.Param(restful.QueryParameter("userID", "用户ID").Required(true).DataType("string"))
	rb.To(waitDoWorkListBuilder)
	rb.Doc("待工作列表")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", []storage.WorkNode{})
	return rb
}

func workFlowQueryBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workFlowID := request.QueryParameter("workFlowID")
	workFlowCode := request.QueryParameter("workFlowCode")
	useStatusV := request.QueryParameter("useStatus")
	useStatus := conv.ToIntDefault(useStatusV, -1)
	s := controller.WorkFlowQuery(workFlowID, workFlowCode, useStatus, getContextValue(request))
	respCtx.Succ(s)
}

// WorkFlowQuery 工作流查询
// api.go  WorkFlowQuery
func WorkFlowQuery(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workFlowID", "工作流ID").DataType("string"))
	rb.Param(restful.QueryParameter("workFlowCode", "工作流编码").DataType("string"))
	rb.Param(restful.QueryParameter("useStatus", "工作流状态(-1=全部,0=未启用,1=启用)").DataType("integer"))
	rb.To(workFlowQueryBuilder)
	rb.Doc("工作流查询")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", []*storage.WorkFlow{})
	return rb
}

func userGroupListBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	s, err := controller.UserGroupList(getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// UserGroupList 用户组列表
// api.go  UserGroupList
func UserGroupList(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.To(userGroupListBuilder)
	rb.Doc("用户组列表")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "[]string 用户组名称列表", []string{})
	return rb
}

func userGroupUserIDQueryBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	userGroupName := request.QueryParameter("userGroupName")
	if userGroupName == "" {
		respCtx.ParamMissing("userGroupName")
		return
	}
	s, err := controller.UserGroupUserIDQuery(userGroupName, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(s)
}

// UserGroupUserIDQuery 用户组用户ID列表
// api.go  UserGroupUserIDQuery
func UserGroupUserIDQuery(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("userGroupName", "用户组名称").Required(true).DataType("string"))
	rb.To(userGroupUserIDQueryBuilder)
	rb.Doc("用户组用户ID列表")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", []string{})
	return rb
}

func userGroupAddUserIDBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	userGroupName := request.QueryParameter("userGroupName")
	if userGroupName == "" {
		respCtx.ParamMissing("userGroupName")
		return
	}
	userID := request.QueryParameter("userID")
	if userID == "" {
		respCtx.ParamMissing("userID")
		return
	}
	err := controller.UserGroupAddUserID(userGroupName, userID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// UserGroupAddUserID 用户组绑定用户
// api.go  UserGroupAddUserID
func UserGroupAddUserID(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("userGroupName", "用户组名称").Required(true).DataType("string"))
	rb.Param(restful.QueryParameter("userID", "用户ID").Required(true).DataType("string"))
	rb.To(userGroupAddUserIDBuilder)
	rb.Doc("用户组绑定用户")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func userGroupDelUserIDBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	userGroupName := request.QueryParameter("userGroupName")
	if userGroupName == "" {
		respCtx.ParamMissing("userGroupName")
		return
	}
	userID := request.QueryParameter("userID")
	if userID == "" {
		respCtx.ParamMissing("userID")
		return
	}
	err := controller.UserGroupDelUserID(userGroupName, userID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(nil)
}

// UserGroupDelUserID 用户组移除用户
// api.go  UserGroupDelUserID
func UserGroupDelUserID(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("userGroupName", "用户组名称").Required(true).DataType("string"))
	rb.Param(restful.QueryParameter("userID", "用户ID").Required(true).DataType("string"))
	rb.To(userGroupDelUserIDBuilder)
	rb.Doc("用户组移除用户")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Do(appTool.RestfulApiResultDo)
	return rb
}

func workNodeQueryByIDBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workDetailID := request.QueryParameter("workDetailID")
	if workDetailID == "" {
		respCtx.ParamMissing("workDetailID")
		return
	}
	W, err := controller.WorkNodeQueryByID(workDetailID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(W)
}

// WorkNodeQueryByID 工作节点信息查询
// api.go  WorkNodeQueryByID
func WorkNodeQueryByID(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workDetailID", "工作节点信息查询").Required(true).DataType("string"))
	rb.To(workNodeQueryByIDBuilder)
	rb.Doc("工作节点信息查询")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", storage.WorkNode{})
	return rb
}

func workQueryByIDBuilder(request *restful.Request, response *restful.Response) {
	respCtx := appTool.RestfulRequest(request, response)
	workID := request.QueryParameter("workID")
	if workID == "" {
		respCtx.ParamMissing("workID")
		return
	}
	W, err := controller.WorkQueryByID(workID, getContextValue(request))
	if err != nil {
		respCtx.Error(err)
		return
	}
	respCtx.Succ(W)
}

// WorkQueryByID 工作查询
// api.go  WorkQueryByID
func WorkQueryByID(rb *restful.RouteBuilder) *restful.RouteBuilder {
	rb.Param(restful.QueryParameter("workDetailID", "工作节点信息查询").Required(true).DataType("string"))
	rb.To(workQueryByIDBuilder)
	rb.Doc("工作查询")
	rb.Metadata("openapi.tags", "WorkFlow")
	rb.Returns(http.StatusOK, "", storage.Work{})
	return rb
}
